﻿using System.Collections.Generic;

namespace Aeon.Framework
{

/// <summary>
/// Selective Singleton pattern for AeonFont.    
/// Works in a single context.
/// 
/// </summary>
public sealed class AeonFontManager : IFontManager
    {
    // --- Attributes:
    
    private List<IFont> fonts;      // Created fonts list.

    // --- Constructor:
    
    public AeonFontManager()
        {
        
        fonts = new List<IFont>();
        }

    // --- Public Methods:

    /// <summary>
    /// Returns the available font or create a new one.
    /// 
    /// </summary>
    public IFont GetFont(FontType style)
        {        
        foreach (IFont f in fonts) if (f.Style.Equals(style) ) return(f);
        
        IFont fnt = new AeonFont(style);
        fonts.Add(fnt);
        
        return(fnt);
        }

    /// <summary>    
    /// Cleans all OpenGL context data. 
    /// 
    /// </summary>
    public void CleanFonts()
        {
        foreach (IFont f in fonts) { f.Dispose(); }
        
        fonts.Clear();
        }

    }


}
